package com.fanqwz.hexieshe.mapper;

import com.fanqwz.hexieshe.domain.Article;
import com.fanqwz.hexieshe.domain.Category;
import com.fanqwz.hexieshe.domain.Comment;
import com.fanqwz.hexieshe.domain.HeadLine;
import com.fanqwz.hexieshe.model.ArticleModel;
import com.fanqwz.hexieshe.model.CategoryModel;
import com.fanqwz.hexieshe.model.CommentModel;
import com.fanqwz.hexieshe.model.HeadLineModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanqw on 2017/7/2.
 */

public class DataMapper {

    public static HeadLineModel transform(HeadLine headLine) {
        HeadLineModel h = new HeadLineModel();
        h.setHeadline(headLine.getTitle());
        h.setContent(headLine.getContent());
        h.setImageUrl(headLine.getImageUrl());
        h.setId(headLine.getId());
        return h;
    }

    public static List<HeadLineModel> transformArticles(List<HeadLine> articles) {
        List<HeadLineModel> models = new ArrayList<>(articles.size());

        for (HeadLine article : articles) {
            HeadLineModel h = transform(article);
            models.add(h);
        }

        return models;
    }

    public static List<CategoryModel> transformCategorys(List<Category> categories) {
        List<CategoryModel> models = new ArrayList<>(categories.size());

        for (Category category : categories) {
            CategoryModel m  = new CategoryModel();
            m.setId(category.getId());
            m.setName(category.getName());
            m.setDisplayName(category.getDisplayName());
            models.add(m);
        }

        return models;
    }

    public static ArticleModel transform(Article article) {
        ArticleModel articleModel = new ArticleModel();
        articleModel.setContent(article.getContent());
        articleModel.setId(article.getID());
        articleModel.setTitle(article.getTitle());
        return articleModel;
    }

    public static List<CommentModel> transformComments(List<Comment> comments) {
        List<CommentModel> models = new ArrayList<>(comments.size());

        for (Comment c : comments) {
            CommentModel model = new CommentModel();
            model.setUserName(c.getAuthor().getName());
            model.setAvatar(c.getAuthor().getAvatar());
            model.setContent(c.getContent());
            models.add(model);
        }

        return models;
    }
}
